package com.qf.controller;


import com.qf.pojo.Classroom;
import com.qf.service.ClassroomService;
import com.qf.utils.ResultMsg;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


@RestController
@RequestMapping("/classroom")
public class ClassroomController {
    @Autowired
    ClassroomService classroomService;

    //分页查看所有
    @GetMapping("/classroomSelectAll")
    public ResultMsg selectAll(@RequestParam(value="page",required=false,defaultValue = "1") int page, @RequestParam(value="limit",required=false,defaultValue = "10")int limit){
        return classroomService.selectAll(page,limit);
    }

    //查看一个
    @GetMapping("/classroomSelectOne")
    public ResultMsg selectOne(int classroomId){
        return classroomService.selectOne(classroomId);
    }

    //修改
    @PutMapping("/classroomUpdate")
    public ResultMsg update(@RequestBody Classroom classroom){
        return classroomService.update(classroom);
    }


    //新增一个教室信息
    @PostMapping("/classroomIsertinto")
    public ResultMsg Isertinto(@RequestBody Classroom classroom){
        return classroomService.isertinto(classroom);
    }

    //删除一个
    @DeleteMapping("/classroomDeleteOne")
    public ResultMsg deleteOne(@RequestBody Map map){
        int classroomId=(Integer)map.get("classroomId");
        return classroomService.deleteOne(classroomId);
    }

    //删除多个
    @DeleteMapping("/classroomDeleteMul")
    public ResultMsg deleteMul(@RequestBody Map<String,List<Integer>> map){
        return classroomService.deleteMul(map.get("classroomIds"));
    }

    //分页,模糊查询
    @GetMapping("/classroomSelectDim")
    public ResultMsg selectDim(@RequestParam(value="page",required=false,defaultValue = "1") int page,@RequestParam(value="limit",required=false,defaultValue = "10")int limit,String classroomName,String classroomType,Integer classroomStatus){
        return classroomService.selectDim(page,limit,classroomName,classroomType,classroomStatus);
    }

    //修改一个教室状态
    @GetMapping("/classroomUpdateStatus")
    public ResultMsg updateStatus(int classroomId,int classroomStatus){
        return classroomService.updateStatus(classroomId,classroomStatus);
    }
    //修改多个教室状态
    @PutMapping("/classroomUpdateStatusMul")
    public ResultMsg updateStatusMul(@RequestBody Map<String,Object> map){
        return classroomService.updateStatusMul((List<Integer>) map.get("classroomIds"),(Integer) map.get("classroomStatus"));
    }
}
